package com.hotel.company.service;

import com.hotel.comm.bean.DubboReply;
import com.hotel.comm.bean.IReply;
import com.hotel.comm.bean.company.EjobDepartment;
import com.hotel.comm.service.company.ICompanyDepartmentService;
import com.hotel.company.Constants;
import com.hotel.company.repository.IEjobDepartmentRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 企业部门service层
 * Created by frank on 15-6-16.
 */
@Service
public class CompanyDepartmentServiceImpl implements ICompanyDepartmentService {

    @Autowired
    IEjobDepartmentRepository ejobDepartmentRepository;

    @Override
    public IReply getById(Long companyDepartmentId) {
        try {
            EjobDepartment ejobDepartment = this.ejobDepartmentRepository.findOne(companyDepartmentId);
            return new DubboReply(ejobDepartment);
        } catch (Exception e) {
            return new DubboReply(Constants.REPLY_CODE_COMPANY_DEPARTMENT_GET_BY_ID, Constants.REPLY_MSG_COMPANY_DEPARTMENT_GET_BY_ID);
        }
    }

    @Override
    public IReply saveOrUpdate(EjobDepartment ejobDepartment) {
        try {
            EjobDepartment department = this.ejobDepartmentRepository.save(ejobDepartment);
            return new DubboReply(department);
        } catch (Exception e) {
            return new DubboReply(Constants.REPLY_CODE_SAVE_COMPANY_DEPARTMENT, Constants.REPLY_MSG_SAVE_COMPANY_DEPARTMENT);
        }
    }

    @Override
    public IReply delete(Long companyDepartmentId) {
        try {
            this.ejobDepartmentRepository.delete(companyDepartmentId);
            return new DubboReply(companyDepartmentId);
        } catch (Exception e) {
            return new DubboReply(Constants.REPLY_CODE_DELETE_COMPANY_DEPARTMENT, Constants.REPLY_MSG_DELETE_COMPANY_DEPARTMENT);
        }
    }
}
